using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using DTO;
using BUS;
using Utility;

namespace BUS
{
    public class TraLoi_BUS
    {
        public static void Insert(TraLoi_DTO TraLoi)
        {
            TraLoi_DAL TraLoiDAL = new TraLoi_DAL ();
            TraLoiDAL.Insert(TraLoi);
        }
        public static void Update(TraLoi_DTO TraLoi)
        {
            TraLoi_DAL TraloiDAL= new TraLoi_DAL ();
            TraloiDAL.Update(TraLoi);
        }
        public static void Delete(int iD)
        {
            TraLoi_DAL TraloiDAL = new TraLoi_DAL ();
            TraloiDAL.Delete(iD);
        }
        public static TraLoiCollection Get(string where,
            int pageindex,
            int pagesize,
            string orderby,
            string orderdirection,
            out int total)
        {
            TraLoi_DAL TraloiDAL = new TraLoi_DAL ();
            return TraloiDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static TraLoiCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            TraLoi_DAL TraloiDAL = new TraLoi_DAL();
            return TraloiDAL.Get(cri.Criter, 0, 0, TraLoiColumns.ID.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static TraLoi_DTO GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, TraLoiColumns.ID.ToString(), Condition.EQUAL, iD);
            TraLoi_DAL TraloiDAL = new TraLoi_DAL();
            TraLoiCollection TlCollection = TraloiDAL.Get(cri.Criter,
                0, 0, TraLoiColumns.ID.ToString(), OrderDirection.ASC.ToString(), out total);
            if (TlCollection.Count > 0)
                return TlCollection[0];
            return null;
        }
        public static TraLoiCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            TraLoi_DAL TraloiDAL = new TraLoi_DAL();
            return TraloiDAL.Get(cri.Criter, 1, number,
                TraLoiColumns.ID.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static TraLoiCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            TraLoi_DAL TraloiDAL = new TraLoi_DAL();
            return TraloiDAL.Get(cri.Criter, 1, number,
                TraLoiColumns.ID.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
}
